#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>

using namespace std;
const int M=1e6+5;
const int N=2e5+5;
const int mod=1e9+7;
ll dp[N],sum[N];int n,a[N],ed[M],nxt[N];

void solve()
{
    memset(ed,0,sizeof(ed));
    memset(dp,0,sizeof(dp));
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1];
        if(i!=1&&a[i]==a[i-1])sum[i]+=a[i];
    }for(int i=n;i>=1;i--){
        nxt[i]=ed[a[i]];
        ed[a[i]]=i;
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        dp[i+1]=max(dp[i],dp[i+1]);
        if(nxt[i]){
            if(nxt[i]==i+1)dp[i+1]=max(dp[i+1],dp[i]+a[i]);
            else{
                ll tmp=dp[i]+sum[nxt[i]-1]-sum[i+1]+a[i];
                dp[nxt[i]-1]=max(dp[nxt[i]-1],tmp);
            }
        }
        ans=max(ans,dp[i]);
    }
    printf("%lld\n",ans);
    return;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--)solve();
    return 0;
}